package com.yuexin.project.statistic.bookDish.controller;

import com.yuexin.common.utils.poi.ExcelUtil;
import com.yuexin.common.utils.security.ShiroUtils;
import com.yuexin.framework.aspectj.lang.annotation.Log;
import com.yuexin.framework.aspectj.lang.enums.BusinessType;
import com.yuexin.framework.web.controller.BaseController;
import com.yuexin.framework.web.domain.AjaxResult;
import com.yuexin.framework.web.page.TableDataInfo;
import com.yuexin.project.statistic.bookDish.domain.StatsBookDish;
import com.yuexin.project.statistic.bookDish.formbean.StatsBookDishFormBean;
import com.yuexin.project.statistic.bookDish.service.IBookDishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品统计 信息操作处理
 * @author Ahanu
 */
@Controller
@RequestMapping("/statistic/bookDish")
@Api(value = "菜品统计 信息操作处理", description = "菜品统计 信息操作处理")
public class StatsBookDishController extends BaseController {
    private String prefix = "statistic/bookdish";
	
	@Autowired
	private IBookDishService bookDishService;

	@RequiresPermissions("statistic:bookDish:view")
	@GetMapping()
	@ApiOperation("统计菜品")
	public String stats(){
		return prefix + "/statsBookDish";
	}

	@RequiresPermissions("statistic:bookDish:list")
	@PostMapping("/list")
    @ResponseBody
	@ApiOperation("统计菜品")
	public TableDataInfo statsBookDish(StatsBookDishFormBean form){
		form.setCompanyId(ShiroUtils.getCompanyId());
		startPage();
		return getDataTable(bookDishService.statsBookDish(form));
	}

	@Log(title = "菜品统计", businessType = BusinessType.EXPORT)
	@RequiresPermissions("statistic:bookDish:export")
	@PostMapping("/export")
	@ResponseBody
	@ApiOperation("统计菜品导出")
	public AjaxResult export(StatsBookDishFormBean form) {
		form.setCompanyId(ShiroUtils.getCompanyId());
		List<StatsBookDish> list = bookDishService.statsBookDish(form);
		ExcelUtil<StatsBookDish> util = new ExcelUtil(StatsBookDish.class);
		return util.exportExcel(list, "菜品统计");
	}
}
